package com.ukao.cashregister.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mcxtzhang.commonadapter.rv.CommonAdapter;
import com.mcxtzhang.commonadapter.rv.ViewHolder;
import com.ukao.cashregister.R;
import com.ukao.cashregister.bean.OrderStateBean;
import com.ukao.cashregister.utils.MyDateUtils;

import java.util.List;

/**
 * Created by ukaodev on 2017/6/14.
 */

public class OrdersStateAdapter extends CommonAdapter<OrderStateBean> {




    public OrdersStateAdapter(Context context, List<OrderStateBean> datas) {
        super(context, datas, R.layout.adapter_orders_state);
    }


    @Override
    public void convert(ViewHolder viewHolder, OrderStateBean item) {
        TextView  title =(TextView)viewHolder.getView(R.id.title);
        View  dine =viewHolder.getView(R.id.dine);
        ImageView  image =(ImageView)viewHolder.getView(R.id.image);
        View  white =viewHolder.getView(R.id.white);
        TextView  time =(TextView)viewHolder.getView(R.id.btn_birthdate);
        int  pos=viewHolder.getLayoutPosition();


        title.setText(item.getShowText());
        if (item.getCreateTime()!=0){
            time.setText(    MyDateUtils.formatDataTime(item.getCreateTime()));
        }





        if (item.isCheck()){
            image.setImageResource(R.drawable.order_check);
            title.setTextColor(mContext.getResources().getColor(R.color.black));
            dine.setBackgroundColor(mContext.getResources().getColor(R.color.Green));
        }else{

            dine.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
            title.setTextColor(mContext.getResources().getColor(R.color.gray_order));
            image.setImageResource(R.drawable.order_no_check);

        }
        List<OrderStateBean>  mdata=getDatas();

        if (pos==0){
            white.setVisibility(View.VISIBLE);
        }else{
            white.setVisibility(View.GONE);
        }
        if (pos==getDatas().size()-1){
            dine.setVisibility(View.GONE);
            white.setBackgroundColor(mContext.getResources().getColor(R.color.green));
            white.setVisibility(View.VISIBLE);
        }



     boolean   checkOne=mdata.get(0).isCheck();
        boolean   checkTwo=mdata.get(1).isCheck();
        boolean   checktheree=mdata.get(2).isCheck();
        boolean   checkfour=mdata.get(3).isCheck();
        boolean   checkfive=mdata.get(4).isCheck();

        switch (pos){
            case  0:
                if (!checkfive&&!checkfour&&!checktheree&&!checkTwo&&checkOne){
                    dine.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
                    white.setBackgroundColor(mContext.getResources().getColor(R.color.white));
                    white.setVisibility(View.VISIBLE);
                };
                break;
            case  1:
                if (!checkfive&&!checkfour&&!checktheree&&!checkTwo&&checkOne){
                    white.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
                    white.setVisibility(View.VISIBLE);
                }else

                if (!checkfive&&!checkfour&&!checktheree&&checkTwo&&checkOne){
                    dine.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
                    white.setBackgroundColor(mContext.getResources().getColor(R.color.green));
                    white.setVisibility(View.VISIBLE);
                };

                break;
            case  2:

                if (!checkfive&&!checkfour&&!checktheree&&checkTwo&&checkOne){
                    white.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
                    white.setVisibility(View.VISIBLE);
                }else

                if (!checkfive&&!checkfour&&checktheree&&checkTwo&&checkOne){
                    dine.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
                    white.setBackgroundColor(mContext.getResources().getColor(R.color.green));
                    white.setVisibility(View.VISIBLE);
                }

                break;
            case  3:

                if (!checkfive&&!checkfour&&checktheree&&checkTwo&&checkOne){
                    white.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
                    white.setVisibility(View.VISIBLE);
                }else if (!checkfive&&checkfour&&checktheree&&checkTwo&&checkOne){
                    dine.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
                    white.setBackgroundColor(mContext.getResources().getColor(R.color.green));
                    white.setVisibility(View.VISIBLE);
                };


                break;
            case  4:
                if (!checkfive||!checkfour||!checktheree||!checkTwo||!checkOne) {
                    white.setBackgroundColor(mContext.getResources().getColor(R.color.gray_order));
                }
                break;
        }

    }






}
